RAIS  3.2
C:/Projekte/RAIS/Specific Masks/App_Code/DynamicMaskControlsManagement.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Data;
00003 using System.Configuration;
00004 using System.Collections.Generic;
00005 using System.Web;
00006 using System.Web.Security;
00007 using System.Web.UI;
00008 using System.Web.UI.WebControls;
00009 using System.Web.UI.WebControls.WebParts;
00010 using System.Web.UI.HtmlControls;
00011 
00012 using RAIS.UI.SpecificMasks.Controls;
00013 using RAIS.UI.Common;
00014 using RAIS.Common.DynamicMaskManagement;
00015 using RAIS.Common.TableManagement;
00016 using RAIS.Common.UserManagement;
00017 using RAIS.UI.SpecificMasks.Dynamic_Masks;
00018 using System.IO;
00019 
00020 namespace RAIS.UI.SpecificMasks
00021 {
00025     public class DynamicMaskControlsManagement
00026         {
00027         public static List<string> deletedLinks = new List<string>();
00034                 public static void AddFieldControls(System.Web.UI.HtmlControls.HtmlTable table, List<FieldData> currentRowValues, int callNumber, EventHandler selectHandler)
00035                 {
00036             //string dateScript = "";
00037                         int controlNumber = 0;
00038                         foreach (FieldData fieldData in currentRowValues)
00039                         {
00040                                 fieldData.RaisedPostback = false;
00041 
00042                                 if (fieldData.Field.VisibleOnForms)
00043                                 {
00044                                         HtmlTableRow row = new HtmlTableRow();
00045                                         HtmlTableCell col1 = new HtmlTableCell();
00046                                         col1.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_LABELS_COLUMN);
00047                                         Label fieldLabel = new Label();
00048                                         fieldLabel.Text = (!string.IsNullOrEmpty(fieldData.Field.LocalLanguageFieldName))
00049                                                 ? fieldData.Field.LocalLanguageFieldName
00050                                                 : fieldData.Field.Name;
00051                                         switch (fieldData.Field.Necessity)
00052                                         {
00053                                                 case Field.NecessityType.Required:
00054                                                         fieldLabel.ForeColor = Constants.COLOR_OF_REQUIRED_FIELD;
00055                                                         break;
00056                                                 case Field.NecessityType.Suggested:
00057                                                         fieldLabel.ForeColor = Constants.COLOR_OF_SUGGESTED_FIELD;
00058                                                         break;
00059                                                 case Field.NecessityType.NotRequired:
00060                                                         fieldLabel.ForeColor = Constants.COLOR_OF_NOT_REQUIRED_FIELD;
00061                                                         break;
00062                                         }       
00063                                         col1.Controls.Add(fieldLabel);
00064                                         row.Cells.Add(col1);
00065 
00066                                         HtmlTableCell col2 = new HtmlTableCell();
00067                                         col2.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_INPUT_CONTROLS_COLUMN);
00068                                         HtmlTableCell col3 = new HtmlTableCell();
00069                                         col3.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_ERROR_MESSAGES_COLUMN);
00070                                         // Add TextBox
00071                                         if (fieldData.Field.Type != Field.FieldType.SingleLookup
00072                                                 && fieldData.Field.Type != Field.FieldType.MultipleLookup
00073                                                 && fieldData.Field.Type != Field.FieldType.Logical
00074                                                 && fieldData.Field.Type != Field.FieldType.Label
00075                         && fieldData.Field.Type != Field.FieldType.Link)
00076                                         {
00077                                                 TextBox textBox = new TextBox();
00078                                                 textBox.ID = string.Format("tb{0}{1}", callNumber, controlNumber.ToString());
00079                                                 fieldData.ControlName = textBox.ID;
00080                                                 textBox.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_TEXT_BOX);
00081                                                 if (fieldData.Field.Size != null)
00082                                                 {
00083                                                         textBox.MaxLength = fieldData.Field.MaxLength;
00084                                                 }
00085 
00086                                                 controlNumber++;
00087 
00088                                                 if (fieldData.Field.Multiline)
00089                                                 {
00090                                                         textBox.TextMode = TextBoxMode.MultiLine;
00091                                                         textBox.Rows = Constants.MULTILINE_TEXTBOX_ROWS_NUMBER;
00092                                                 }
00093 
00094                                                 if (fieldData.Field.HighField)
00095                                                 {
00096                                                         textBox.TextMode = TextBoxMode.MultiLine;
00097                                                         textBox.Rows = Constants.HIGHFIELD_TEXTBOX_ROWS_NUMBER;
00098                                                 }
00099 
00100                                                 if (fieldData.Field.Type == Field.FieldType.LookupPlusIntegerValue
00101                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue)
00102                                                         textBox.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_LOOKUP_WITH_NUMBER_TEXT_BOX);
00103 
00104                                                 if (fieldData.Field.Type == Field.FieldType.Date)
00105                                                         textBox.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_DATE_TEXT_BOX);
00106                                                         
00107                                                 col2.Controls.Add(textBox);
00108 
00109                                                 if (fieldData.Field.Type == Field.FieldType.Date)
00110                                                 {
00111                                                         Label lblDateFormat = new Label();
00112                                                         lblDateFormat.Text = DynamicMaskManagement.GetNationalDateFormatString(true);
00113                                                         lblDateFormat.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_DATE_FORMAT_LABEL);
00114 
00115                                                         col2.Controls.Add(lblDateFormat);
00116                                                 }
00117 
00118                                                 //---- VALIDATORS
00119                                                 // Text - check length for multiline textboxes
00120                                                 if (fieldData.Field.Type == Field.FieldType.Text
00121                                                         && (fieldData.Field.Multiline || fieldData.Field.HighField)
00122                                                         && fieldData.Field.MaxLength != 0)
00123                                                 {
00124                                                         UserData currentUser = (UserData)table.Page.Session[UI.Common.Constants.CURRENT_USER_TAG];
00125                                                         string translatedMessage = RAIS.ApplicationLogicLayer.Localisation.Translate(string.Format(RAIS.Common.Messages.TEXT_TOO_LONG, fieldData.Field.MaxLength),
00126                                                                                                                                                                                                                 RAIS.Common.Messages.TRANSLATION_CONTEXT,
00127                                                                                                                                                                                                                 RAIS.Common.Constants.DEFAULT_LANGUAGE,
00128                                                                                                                                                                                                                 currentUser.Language);
00129 
00130                                                         CustomValidator validator = new CustomValidator();
00131                                                         validator.ControlToValidate = textBox.ID;
00132                                                         validator.ServerValidate += DynamicMaskControlsManagement.MultilineTextValidation;
00133                                                         validator.ErrorMessage = translatedMessage;
00134                                                         col3.Controls.Add(validator);
00135                                                 }
00136 
00137                                                 // Integer
00138                                                 if (fieldData.Field.Type == Field.FieldType.Numeric
00139                                                         && (fieldData.Field.Size == Field.FieldSize.Integer
00140                                                                 || fieldData.Field.Size == Field.FieldSize.TimeInterval
00141                                                                 || fieldData.Field.Size == Field.FieldSize.Year)
00142                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusIntegerValue)
00143                                                 {
00144                                                         UserData currentUser = (UserData)table.Page.Session[UI.Common.Constants.CURRENT_USER_TAG];
00145                                                         string translatedMessage = RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.Common.Messages.WRONG_INTEGER_VALUE,
00146                                                                                                                                                                                                                 RAIS.Common.Messages.TRANSLATION_CONTEXT,
00147                                                                                                                                                                                                                 RAIS.Common.Constants.DEFAULT_LANGUAGE,
00148                                                                                                                                                                                                                 currentUser.Language);
00149 
00150                                                         RegularExpressionValidator validator = new RegularExpressionValidator();
00151                                                         validator.ControlToValidate = textBox.ID;
00152                                                         validator.ValidationExpression = Constants.INTEGER_VALIDATION_EXPRESSION;
00153                                                         validator.ErrorMessage = translatedMessage;
00154                                                         col3.Controls.Add(validator);
00155                                                 }
00156 
00157                                                 // Rational and scientific values
00158                                                 if (fieldData.Field.Type == Field.FieldType.Numeric
00159                                                         && (fieldData.Field.Size == Field.FieldSize.Rational
00160                                                                 || fieldData.Field.Size == Field.FieldSize.Scientific)
00161                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue)
00162                                                 {
00163                                                         UserData currentUser = (UserData)table.Page.Session[UI.Common.Constants.CURRENT_USER_TAG];
00164                                                         string translatedMessage = RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.Common.Messages.WRONG_RATIONAL_VALUE,
00165                                                                                                                                                                                                                 RAIS.Common.Messages.TRANSLATION_CONTEXT,
00166                                                                                                                                                                                                                 RAIS.Common.Constants.DEFAULT_LANGUAGE,
00167                                                                                                                                                                                                                 currentUser.Language);
00168 
00169                                                         RegularExpressionValidator validator = new RegularExpressionValidator();
00170                                                         validator.ControlToValidate = textBox.ID;
00171                                                         validator.ValidationExpression = Constants.RATIONAL_VALIDATION_EXPRESSION;
00172                                                         validator.ErrorMessage = translatedMessage;
00173                                                         col3.Controls.Add(validator);
00174                                                 }
00175 
00176                                                 // Required fields
00177                                                 if (fieldData.Field.Necessity == Field.NecessityType.Required)
00178                                                 {
00179                                                         UserData currentUser = (UserData)table.Page.Session[UI.Common.Constants.CURRENT_USER_TAG];
00180                                                         string translatedMessage = RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.Common.Messages.FIELD_IS_MANDATORY,
00181                                                                                                                                                                                                                 RAIS.Common.Messages.TRANSLATION_CONTEXT,
00182                                                                                                                                                                                                                 RAIS.Common.Constants.DEFAULT_LANGUAGE,
00183                                                                                                                                                                                                                 currentUser.Language);
00184 
00185                                                         RequiredFieldValidator validator = new RequiredFieldValidator();
00186                                                         validator.ControlToValidate = textBox.ID;
00187                                                         validator.ErrorMessage = translatedMessage;
00188 
00189                                                         col3.Controls.Add(validator);
00190                                                 }
00191                                         }
00192 
00193                     //HyperLink
00194                     if (fieldData.Field.Type == Field.FieldType.Link)
00195                     {
00196                         controlNumber++;
00197                         AddLinkField(table, col2, col3, controlNumber, callNumber, fieldData);
00198                     }
00199 
00200                                         // Check TextBox
00201                                         if (fieldData.Field.Type == Field.FieldType.Logical)
00202                                         {
00203                                                 CheckBox checkBox = new CheckBox();
00204                                                 controlNumber++;
00205 
00206                                                 col2.Controls.Add(checkBox);
00207                                         }
00208 
00209                                         // Add drop-down list
00210                                         if (fieldData.Field.Type == Field.FieldType.SingleLookup
00211                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusIntegerValue
00212                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue
00213                                                 )
00214                                         {
00215                                                 DropDownList ddList = new DropDownList();
00216                                                 ddList.ID = string.Format("ddl{0}{1}", callNumber, controlNumber.ToString());
00217                                                 fieldData.ControlName = ddList.ID;
00218                                                 if (fieldData.IsUsedAsParameter )
00219                                                         ddList.SelectedIndexChanged += selectHandler;
00220                                                 controlNumber++;
00221 
00222                                                 if (fieldData.Field.Type == Field.FieldType.LookupPlusIntegerValue
00223                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue)
00224                                                         ddList.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_LOOKUP_WITH_NUMBER_DROP_DOWN);
00225                                                 else
00226                                                         ddList.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_SINGLE_LOOKUP_DROPDOWN);
00227 
00228                                                 col2.Controls.Add(ddList);
00229 
00230                                                 // Required fields validation
00231                                                 if (fieldData.Field.Necessity == Field.NecessityType.Required)
00232                                                 {
00233                                                         UserData currentUser = (UserData)table.Page.Session[UI.Common.Constants.CURRENT_USER_TAG];
00234                                                         string translatedMessage = RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.Common.Messages.FIELD_IS_MANDATORY,
00235                                                                                                                                                                                                                 RAIS.Common.Messages.TRANSLATION_CONTEXT,
00236                                                                                                                                                                                                                 RAIS.Common.Constants.DEFAULT_LANGUAGE,
00237                                                                                                                                                                                                                 currentUser.Language);
00238 
00239                             RequiredFieldValidator validator = new RequiredFieldValidator();
00240                             validator.ID = "validator_of_" + ddList.ID;
00241                                                         validator.ControlToValidate = ddList.ID;
00242                                                         validator.InitialValue = "0";
00243                                                     validator.EnableViewState = false;
00244                                                         validator.ErrorMessage = translatedMessage;
00245 
00246                                                         col3.Controls.Add(validator);
00247                                                 }
00248                                         }
00249 
00250                                         // Add MultipleLookup control
00251                                         if (fieldData.Field.Type == Field.FieldType.MultipleLookup)
00252                                         {
00253                                                 MultiLookupFieldControl multiLookup = 
00254                                                         (MultiLookupFieldControl)table.Page.LoadControl("~/Controls/MultiLookupFieldControl.ascx");
00255 
00256                                                 // Set Non-Compliance property
00257                                                 if (fieldData.NonComplianceMultilookup)
00258                                                 {
00259                                                         multiLookup.NonCompliance = true;
00260                                                         multiLookup.NonComplianceMajorCategoryDDL.SelectedIndexChanged += selectHandler;
00261                                                         multiLookup.NonComplianceCategoryDDL.SelectedIndexChanged += selectHandler;
00262                                                 }
00263 
00264                                                 col2.Controls.Add(multiLookup);
00265                                         }
00266                                         row.Cells.Add(col2);
00267                                         row.Cells.Add(col3);
00268 
00269                                         table.Rows.Add(row);
00270                                 }
00271                         }
00272                 }
00273 
00274         static void btnDelete_Command(object sender, CommandEventArgs e)
00275         {
00276             HtmlTable controlTab = ((System.Web.UI.Control)(sender)).Parent.Parent.Parent as HtmlTable;
00277             HyperLink link = controlTab.Rows[0].Cells[0].Controls[0] as HyperLink;
00278             link.Text = "no file";
00279             link.NavigateUrl = "";
00280             ((Button)sender).Style["display"] = "none";
00281             deletedLinks.Add(e.CommandName);
00282         }
00283 
00290         public static void InitializeFieldControls(System.Web.UI.HtmlControls.HtmlTable htmlTable, List<FieldData> currentRowValues)
00291                 {
00292                         int rowNumber = 0;
00293             deletedLinks.Clear();
00294                         foreach (FieldData fieldData in currentRowValues)
00295                         {
00296                                 if (fieldData.Field.VisibleOnForms)
00297                                 {
00298                                         if (fieldData.Field.Name == RAIS.Common.Constants.AUTHORIZATION_PROCESS_NUMBER_FIELD_NAME)
00299                                                 htmlTable.Page.Session[UI.Common.Constants.AUTHORIZATION_PROCESS_NUMBER_TAG] = fieldData.Value;
00300 
00301                                         if (fieldData.Field.Name == RAIS.Common.Constants.AUTHORIZATION_STATUS_NUMBER_FIELD_NAME
00302                                                 && fieldData.Value == string.Empty
00303                                                 && htmlTable.Page.Session[UI.Common.Constants.AUTHORIZATION_PROCESS_NUMBER_TAG] != null)
00304                                         {
00305                                                 fieldData.Value = htmlTable.Page.Session[UI.Common.Constants.AUTHORIZATION_PROCESS_NUMBER_TAG].ToString();
00306                                         }
00307 
00308                     if (fieldData.Field.Name == RAIS.Common.Constants.ENFORCEMENT_PROCESS_NUMBER_FIELD_NAME)
00309                         htmlTable.Page.Session[UI.Common.Constants.ENFORCEMENT_PROCESS_NUMBER_TAG] = fieldData.Value;
00310 
00311                     if (fieldData.Field.Name == RAIS.Common.Constants.ENFORCEMENT_STATUS_NUMBER_FIELD_NAME
00312                         && fieldData.Value == string.Empty
00313                         && htmlTable.Page.Session[UI.Common.Constants.ENFORCEMENT_PROCESS_NUMBER_TAG] != null)
00314                     {
00315                         fieldData.Value = htmlTable.Page.Session[UI.Common.Constants.ENFORCEMENT_PROCESS_NUMBER_TAG].ToString();
00316                     }
00317 
00318 
00319 
00320                                         ((Label)htmlTable.Rows[rowNumber].Cells[0].Controls[0]).Text = 
00321                                                 (!string.IsNullOrEmpty(fieldData.Field.LocalLanguageFieldName))
00322                                                         ? fieldData.Field.LocalLanguageFieldName
00323                                                         : fieldData.Field.Name;
00324                                         int controlNumber = 0;
00325 
00326                                         // Fields with typed by user value
00327                                         if (fieldData.Field.Type != Field.FieldType.SingleLookup
00328                                                 && fieldData.Field.Type != Field.FieldType.MultipleLookup
00329                                                 && fieldData.Field.Type != Field.FieldType.Logical
00330                                                 && fieldData.Field.Type != Field.FieldType.Label
00331                         && fieldData.Field.Type != Field.FieldType.Link)
00332                                         {
00333                                                 string value = fieldData.Value;
00334 
00335                                                 // Format rational and scientific numeric
00336                                                 if (fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue
00337                                                         || fieldData.Field.Type == Field.FieldType.Numeric
00338                                                                 && (fieldData.Field.Size == Field.FieldSize.Rational
00339                                                                         || fieldData.Field.Size == Field.FieldSize.Scientific))
00340                                                 {
00341                                                         double numericValue = (fieldData.Value == string.Empty) ? 0 : double.Parse(fieldData.Value);
00342                                                         string formatString = (fieldData.Field.Size == Field.FieldSize.Rational)
00343                                                                 ? RAIS.UI.Common.Constants.RATIONAL_VALUE_FORMAT
00344                                                                 : RAIS.UI.Common.Constants.SCIENTIFIC_VALUE_FORMAT;
00345                                                         value = string.Format(formatString, numericValue);
00346                                                 }
00347 
00348                                                 ((TextBox)htmlTable.Rows[rowNumber].Cells[1].Controls[controlNumber]).Text = value;
00349                                                 controlNumber++;
00350                                         }
00351 
00352                                         // Link field
00353                     if (fieldData.Field.Type == Field.FieldType.Link)
00354                     {                        
00355                         InitializeField(htmlTable, fieldData, controlNumber, rowNumber);
00356                         controlNumber++;
00357                     }
00358 
00359                                         // Checkbox field
00360                                         if (fieldData.Field.Type == Field.FieldType.Logical)
00361                                         {
00362                                                 int fieldValue = 0;
00363                                                 bool isChecked = false;
00364                                                 int.TryParse(fieldData.Value, out fieldValue);
00365                                                 isChecked = (fieldValue == 1);
00366 
00367                                                 ((CheckBox)htmlTable.Rows[rowNumber].Cells[1].Controls[controlNumber]).Checked = isChecked;
00368                                                 controlNumber++;
00369                                         }
00370 
00371                                         // Lookup fields
00372                                         if (fieldData.Field.Type == Field.FieldType.SingleLookup
00373                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusIntegerValue
00374                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue
00375                                                 )
00376                                         {
00377                                                 DropDownList ddList = (DropDownList)htmlTable.Rows[rowNumber].Cells[1].Controls[controlNumber];
00378                                                 ddList.AutoPostBack = fieldData.IsUsedAsParameter;
00379 
00380                                                 ddList.Items.Clear();
00381                                                 //if (fieldData.LookupValues != null && fieldData.LookupValues.Count != 0)
00382                                                 if (fieldData.VisibleLookupValues != null && fieldData.VisibleLookupValues.Count != 0)
00383                                                         {
00384                                                         ListItem emptyLI = new ListItem(string.Empty, 0.ToString());
00385                                                         ddList.Items.Add(emptyLI);
00386 
00387                                                         //foreach (KeyValuePair<int, string> lookupValue in fieldData.LookupValues)
00388                                                         //{
00389                                                         //    ListItem li = new ListItem(lookupValue.Value, lookupValue.Key.ToString());
00390                                                         //    if (lookupValue.Key == fieldData.CurrentLookupValue)
00391                                                         //        li.Selected = true;
00392                                                         //    ddList.Items.Add(li);
00393                                                         //}
00394                                                         foreach (KeyValuePair<string, string> lookupValue in fieldData.VisibleLookupValues)
00395                                                         {
00396                                                                 ListItem li = new ListItem(lookupValue.Value, lookupValue.Key.ToString());
00397                                                                 if (lookupValue.Key == fieldData.CurrentVisibleLookupValue)
00398                                                                         li.Selected = true;
00399                                                                 ddList.Items.Add(li);
00400                                                         }
00401                                                 }
00402                                                 else
00403                                                 {
00404                                                         //ddList.Items.Add(new ListItem(fieldData.CurrentLookupText, fieldData.CurrentLookupValue.ToString()));
00405                                                         ddList.Items.Add(new ListItem(fieldData.CurrentVisibleLookupText, fieldData.CurrentVisibleLookupValue));
00406 
00407                             //update validators for empty lookups
00408                             if ((ddList.Items.Count == 1)&&(ddList.Items[0].Text == string.Empty))
00409                             {
00410                                 RequiredFieldValidator compareValidator =
00411                                     (RequiredFieldValidator)
00412                                     htmlTable.Rows[rowNumber].Cells[1].FindControl("validator_of_" + ddList.ID);
00413                                 if (compareValidator != null)
00414                                 {
00415                                     compareValidator.InitialValue = "";
00416                                     compareValidator.IsValid = false;
00417                                 }
00418                             }
00419                                                 }
00420                                         }
00421 
00422                                         // Multilookup fields
00423                                         if (fieldData.Field.Type == Field.FieldType.MultipleLookup)
00424                                         {
00425                                                 // Fill in target listbox
00426                                                 ListBox listBoxTarget = ((MultiLookupFieldControl)htmlTable.Rows[rowNumber].Cells[1].Controls[0]).TargetListBox;
00427                                                 listBoxTarget.Items.Clear();
00428                                                 Dictionary<string, string> lookupValues = (fieldData.SavedVisibleSelectedMultiLookupValues != null)
00429                                                         ? fieldData.SavedVisibleSelectedMultiLookupValues
00430                                                         : fieldData.VisibleSelectedMultiLookupValues;
00431                                                 if (lookupValues != null)
00432                                                 {
00433                                                         foreach (KeyValuePair<string, string> lookupValue in lookupValues)
00434                                                         {
00435                                                                 listBoxTarget.Items.Add(new ListItem(lookupValue.Value, lookupValue.Key));
00436                                                         }
00437                                                         UI.Common.PageManagement.InitializeListboxTooltips(listBoxTarget);
00438                                                 }
00439 
00440                                                 // Fill in source listbox 
00441                                                 ListBox listBoxSource = ((MultiLookupFieldControl)htmlTable.Rows[rowNumber].Cells[1].Controls[0]).SourceListBox;
00442                                                 listBoxSource.Items.Clear();
00443                                                 lookupValues = (fieldData.SavedVisibleLookupValues != null)
00444                                                         ? fieldData.SavedVisibleLookupValues
00445                                                         : fieldData.VisibleLookupValues;
00446                                                 if (lookupValues != null)
00447                                                 {
00448                                                         foreach (KeyValuePair<string, string> lookupValue in lookupValues)
00449                                                         {
00450                                                                 ListItem listItem = new ListItem(lookupValue.Value, lookupValue.Key);
00451                                                                 if (!listBoxTarget.Items.Contains(listItem))
00452                                                                         listBoxSource.Items.Add(listItem);
00453                                                         }
00454                             UI.Common.PageManagement.InitializeListboxTooltips(listBoxSource);
00455                                                 }
00456                                         }
00457                                         rowNumber++;
00458                                 }
00459                         }
00460                 }
00461 
00462                 static public void SetSinglelookupFieldsPreselectedValues(System.Web.UI.HtmlControls.HtmlTable htmlTable, DynamicMaskData dynamicMaskData, Dictionary<int, int> filterValues)
00463                 {
00464                         if (filterValues != null)
00465                         {
00466                                 int rowNumber = 0;
00467                                 foreach (FieldData fieldData in dynamicMaskData.CurrentRowValues)
00468                                 {
00469                                         if (fieldData.Field.VisibleOnForms)
00470                                         {
00471                                                 if (fieldData.Field.RelatedTable != null
00472                                                         && filterValues.ContainsKey(fieldData.Field.RelatedTable.ID))
00473                                                 {
00474                                                         if (fieldData.Field.Type == Field.FieldType.SingleLookup)
00475                                                         {
00476                                                                 DropDownList dropDownList = (DropDownList)htmlTable.Rows[rowNumber].Cells[1].Controls[0];
00477                                                                 string key = FieldData.MakeKey(fieldData.Field.Name, filterValues[fieldData.Field.RelatedTable.ID]);
00478                                                                 ListItem selectedListItem = dropDownList.Items.FindByValue(key);
00479                                                                 if (selectedListItem != null)
00480                                                                 {
00481                                                                         selectedListItem.Selected = true;
00482                                                                         //fieldData.CurrentLookupValue = filterValues[fieldData.Field.RelatedTable.ID];
00483                                                                 }
00484                                                         }
00485                                                 }
00486                                                 rowNumber++;
00487                                         }
00488                                 }
00489                         }
00490                 }
00491 
00492                 static public void SetMultilookupFieldsPreselectedValues(System.Web.UI.HtmlControls.HtmlTable htmlTable, DynamicMaskData dynamicMaskData, Dictionary<int, int> filterValues)
00493                 {
00494                         if (filterValues != null)
00495                         {
00496                                 int rowNumber = 0;
00497                                 foreach (FieldData fieldData in dynamicMaskData.CurrentRowValues)
00498                                 {
00499                                         if (fieldData.Field.VisibleOnForms)
00500                                         {
00501                                                 if (fieldData.Field.RelatedTable != null
00502                                                         && filterValues.ContainsKey(fieldData.Field.RelatedTable.ID))
00503                                                 {
00504                                                         if (fieldData.Field.Type == Field.FieldType.MultipleLookup)
00505                                                         {
00506                                                                 ListBox listBoxSource = ((MultiLookupFieldControl)htmlTable.Rows[rowNumber].Cells[1].Controls[0]).SourceListBox;
00507                                                                 ListBox listBoxTarget = ((MultiLookupFieldControl)htmlTable.Rows[rowNumber].Cells[1].Controls[0]).TargetListBox;
00508                                                                 ListItem selectedListItem = listBoxSource.Items.FindByValue(FieldData.MakeKey(fieldData.Field.Name, filterValues[fieldData.Field.RelatedTable.ID]));
00509                                                                 if (selectedListItem != null)
00510                                                                 {
00511                                                                         listBoxSource.Items.Remove(selectedListItem);
00512                                                                         listBoxTarget.Items.Add(selectedListItem);
00513                                                                 }
00514                                                         }
00515                                                 }
00516                                                 rowNumber++;
00517                                         }
00518                                 }
00519                         }
00520                 }
00527         public static void InitializeObjectFromControlsValues(System.Web.UI.HtmlControls.HtmlTable table, DynamicMaskData dynamicMaskData)
00528                 {
00529                         table.Page.Session[UI.Common.Constants.DOWNLOAD_FILES_LIST] = null;
00530                         int rowNumber = 0;
00531                         string foreignKeyFieldName = 
00532                                 dynamicMaskData.DynamicMask.Table.GetForeignKeyFieldNameByTableID(
00533                     dynamicMaskData.DynamicMasks[0].Table.ID);
00534 
00535                         foreach (FieldData fieldData in dynamicMaskData.CurrentRowValues)
00536                         {
00537                                 if (fieldData.Field.Name == RAIS.Common.Constants.AUTHORIZATION_TYPE_FIELD_NAME)
00538                                         fieldData.Value = dynamicMaskData.DynamicMask.AuthorizationType;
00539 
00540                                 if (fieldData.Field.ForeignKeyFieldName == foreignKeyFieldName)
00541                                         fieldData.CurrentLookupValue = dynamicMaskData.ParentID;
00542 
00543                                 if (fieldData.Field.VisibleOnForms)
00544                                 {
00545                                         int controlNumber = 0;
00546                                         if (fieldData.Field.Type != Field.FieldType.SingleLookup
00547                                                 && fieldData.Field.Type != Field.FieldType.MultipleLookup
00548                                                 && fieldData.Field.Type != Field.FieldType.Logical
00549                                                 && fieldData.Field.Type != Field.FieldType.Label
00550                         && fieldData.Field.Type != Field.FieldType.Link)
00551                                         {
00552                                                 fieldData.Value = ((TextBox)table.Rows[rowNumber].Cells[1].Controls[controlNumber]).Text;
00553                         if (fieldData.Field.Name == RAIS.Common.Constants.AUTHORIZATION_PROCESS_NUMBER_FIELD_NAME)
00554                             table.Page.Session[UI.Common.Constants.AUTHORIZATION_PROCESS_NUMBER_TAG] = fieldData.Value;
00555 
00556                         if (fieldData.Field.Name == RAIS.Common.Constants.ENFORCEMENT_PROCESS_NUMBER_FIELD_NAME)
00557                             table.Page.Session[UI.Common.Constants.ENFORCEMENT_PROCESS_NUMBER_TAG] = fieldData.Value;
00558 
00559 
00560                                                 controlNumber++;
00561                                         }
00562 
00563                                         if (fieldData.Field.Type == Field.FieldType.Logical)
00564                                         {
00565                                                 fieldData.Value = (((CheckBox)table.Rows[rowNumber].Cells[1].Controls[controlNumber]).Checked)
00566                                                         ? 1.ToString()
00567                                                         : 0.ToString();
00568                                                 controlNumber++;
00569                                         }
00570 
00571                     if (fieldData.Field.Type == Field.FieldType.Link)
00572                     {
00573                         HtmlTable controlTab = table.Rows[rowNumber].Cells[1].Controls[0] as HtmlTable;
00574 
00575                         FileUpload fileUpload = controlTab.Rows[1].Cells[0].Controls[0] as FileUpload;
00576 
00577                         if (fileUpload.HasFile)
00578                         {
00579                             string directory= ConfigurationManager.AppSettings["UploadDirectory"];
00580                             
00581                             if (!Directory.Exists(directory))
00582                                 Directory.CreateDirectory(directory);
00583                             fileUpload.SaveAs(directory +"\\"+ fileUpload.FileName);
00584                             fieldData.Value = fileUpload.FileName;
00585                         }
00586                         else if (deletedLinks.Contains(fieldData.Field.Name))
00587                         {
00588                             string fileName = ConfigurationManager.AppSettings["UploadDirectory"] + "\\" + fieldData.Value;
00589                             if (File.Exists(fileName))
00590                                 File.Delete(fileName);
00591                             fieldData.Value = "";
00592                         }
00593                     }
00594 
00595                                         if (fieldData.Field.Type == Field.FieldType.SingleLookup
00596                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusIntegerValue
00597                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue
00598                                                 )
00599                                         {
00600                                                 DropDownList ddList = (DropDownList)table.Rows[rowNumber].Cells[1].Controls[controlNumber];
00601                                                 fieldData.CurrentLookupValue = 0;
00602                                                 fieldData.CurrentLookupText = string.Empty;
00603                         if (ddList.SelectedItem != null)
00604                         {
00605                                                         //fieldData.CurrentLookupValue = int.Parse(ddList.SelectedItem.Value);
00606                                                         //fieldData.CurrentLookupText = ddList.SelectedItem.Text;
00607                                                         fieldData.AssignCurrentVisibleLookupValueAndText(ddList.SelectedItem.Value, ddList.SelectedItem.Text);
00608                         }
00609                                         }
00610 
00611                                         if (fieldData.Field.Type == Field.FieldType.MultipleLookup)
00612                                         {
00613                                                 // Fill SavedVisibleLookupValues
00614                                                 // from Source ListBox
00615                                                 MultiLookupFieldControl multilookupFieldControl = (MultiLookupFieldControl)table.Rows[rowNumber].Cells[1].Controls[0];
00616                                                 fieldData.NonComplianceMajorCategoryID = multilookupFieldControl.SelectedNonComplianceMajorCategoryID;
00617                                                 fieldData.NonComplianceCategoryID = multilookupFieldControl.SelectedNonComplianceCategoryID;
00618 
00619                                                 //ListBox listBox = ((MultiLookupFieldControl)table.Rows[rowNumber].Cells[1].Controls[0]).SourceListBox;
00620                                                 ListBox listBox = multilookupFieldControl.SourceListBox;
00621 
00622                                                 if (fieldData.SavedVisibleLookupValues == null)
00623                                                         fieldData.SavedVisibleLookupValues = new Dictionary<string, string>();
00624                                                 else
00625                                                         fieldData.SavedVisibleLookupValues.Clear();
00626 
00627                                                 foreach (ListItem listItem in listBox.Items)
00628                                                 {
00629                                                         fieldData.SavedVisibleLookupValues.Add(listItem.Value, listItem.Text);
00630                                                 }
00631 
00632                                                 // Fill NewMultiLookupValues and SavedVisibleSelectedMultiLookupValues
00633                                                 // from Target ListBox
00634                                                 //listBox = ((MultiLookupFieldControl)table.Rows[rowNumber].Cells[1].Controls[0]).TargetListBox;
00635                                                 listBox = multilookupFieldControl.TargetListBox;
00636                                                 if (fieldData.NewMultiLookupValues == null)
00637                                                         fieldData.NewMultiLookupValues = new Dictionary<int, string>();
00638                                                 else
00639                                                         fieldData.NewMultiLookupValues.Clear();
00640 
00641                                                 if (fieldData.SavedVisibleSelectedMultiLookupValues == null)
00642                                                         fieldData.SavedVisibleSelectedMultiLookupValues = new Dictionary<string, string>();
00643                                                 else
00644                                                         fieldData.SavedVisibleSelectedMultiLookupValues.Clear();
00645 
00646                                                 foreach (ListItem listItem in listBox.Items)
00647                                                 {
00648                                                         fieldData.AddNewMultiLookupValue(listItem.Value, listItem.Text);
00649                                                         fieldData.SavedVisibleSelectedMultiLookupValues.Add(listItem.Value, listItem.Text);
00650                                                 }
00651                                         }
00652                                         rowNumber++;
00653                                 }
00654                         }
00655                 }
00656 
00657                 public static void MultilineTextValidation(object source, ServerValidateEventArgs args)
00658                 {
00659                         TextBox textBox = null;
00660                         CustomValidator cv = (CustomValidator)source;
00661                         Control control = cv.Page.FindControl(cv.ControlToValidate);
00662                         if (control != null)
00663                         {
00664                                 textBox = (TextBox)control;
00665                                 args.IsValid = (args.Value.Length <= textBox.MaxLength 
00666                                         || textBox.MaxLength == 0);
00667                         }
00668                 }
00669 
00670                 static public void SetFieldControlsEnabled(System.Web.UI.HtmlControls.HtmlTable table, List<FieldData> currentRowValues, bool controlsEnabled)
00671                 {
00672                         int rowNumber = 0;
00673                         foreach (FieldData fieldData in currentRowValues)
00674                         {
00675                                 if (fieldData.Field.VisibleOnForms)
00676                                 {
00677                                         bool enabled = controlsEnabled && !fieldData.Field.ReadOnly;
00678                                         int controlNumber = 0;
00679                                         Control control = table.Rows[rowNumber].Cells[0].Controls[controlNumber];
00680                                         ((WebControl)control).Enabled = true; // controlsEnabled;
00681 
00682                                         if (table.Rows[rowNumber].Cells[1].Controls.Count > 0)
00683                                         {
00684                                                 control = table.Rows[rowNumber].Cells[1].Controls[0];
00685                         if (fieldData.Field.Type == Field.FieldType.Link)
00686                         {
00687                             HtmlTable controlTab = table.Rows[rowNumber].Cells[1].Controls[0] as HtmlTable;
00688                             HyperLink link = controlTab.Rows[0].Cells[0].Controls[0] as HyperLink;
00689                             FileUpload file = controlTab.Rows[1].Cells[0].Controls[0] as FileUpload;
00690                             Button delete = controlTab.Rows[0].Cells[1].Controls[0] as Button;
00691 
00692                             link.Enabled = true;
00693                             if (link.Text == "")
00694                             {
00695                                 link.Text = "No file";
00696                                 link.NavigateUrl = "";
00697                             }
00698                             bool deleteEnebled = fieldData.Field.Necessity != Field.NecessityType.Required &&
00699                                 fieldData.Value != "" && File.Exists(ConfigurationManager.AppSettings["UploadDirectory"] + "\\" + fieldData.Value);
00700 
00701                             delete.Style["display"] = controlsEnabled && deleteEnebled ? "block" : "none";
00702                             file.Style["display"] = controlsEnabled ? "block" : "none";
00703                         }
00704                         else if (control is WebControl)
00705                             ((WebControl)control).Enabled = enabled;
00706                         else if (control is UserControl)
00707                             ((MultiLookupFieldControl)control).Enabled = enabled;
00708 
00709                                                 if (fieldData.Field.Type == Field.FieldType.LookupPlusIntegerValue
00710                                                         || fieldData.Field.Type == Field.FieldType.LookupPlusScientificValue)
00711                                                 {
00712                                                         controlNumber++;
00713                                                         ((WebControl)table.Rows[rowNumber].Cells[1].Controls[controlNumber]).Enabled = enabled;
00714                                                 }
00715                                         }
00716 
00717                                         foreach (Control validationControl in table.Rows[rowNumber].Cells[2].Controls)
00718                                                 ((WebControl)validationControl).Enabled = controlsEnabled;
00719 
00720                                         rowNumber++;
00721                                 }
00722                         }
00723 
00724                         //foreach (HtmlTableRow row in table.Rows)
00725                         //    foreach (HtmlTableCell cell in row.Cells)
00726                         //        foreach (Control control in cell.Controls)
00727                         //            if (control is WebControl)
00728                         //                ((WebControl)control).Enabled = controlsEnabled;
00729                         //            else if (control is UserControl)
00730                         //                ((MultiLookupFieldControl)control).Enabled = controlsEnabled;
00731                 }
00732 
00733         static private void AddLinkField(HtmlTable table, HtmlTableCell col2, HtmlTableCell col3, int controlNumber, int callNumber, FieldData fieldData)
00734         {
00735             HyperLink link = new HyperLink();
00736             link.ID = string.Format("link{0}{1}", callNumber, controlNumber.ToString());
00737             link.Target = "_blank";
00738 
00739             FileUpload file = new FileUpload();
00740             file.ID = string.Format("file{0}{1}", callNumber, controlNumber.ToString());
00741             file.Attributes.Add(Constants.ATTRIBUTE_CLASS_NAME, Constants.CSS_CLASS_DM_SINGLE_LOOKUP_DROPDOWN);
00742 
00743             Button btnDelete = new Button();
00744             btnDelete.CausesValidation = false;
00745             btnDelete.Text = "Remove file";
00746             btnDelete.Command += btnDelete_Command;
00747             btnDelete.OnClientClick = string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DELETE_QUESTION_FILE.Replace("'", "\\'"));
00748             btnDelete.ID = string.Format("btndelete{0}{1}", callNumber, controlNumber.ToString());
00749 
00750 
00751             HtmlTable tab = new HtmlTable();
00752             HtmlTableRow row = new HtmlTableRow();
00753             HtmlTableCell cell = new HtmlTableCell();
00754 
00755             cell.Controls.Add(link);
00756             row.Cells.Add(cell);
00757             cell = new HtmlTableCell();
00758             cell.Style[HtmlTextWriterStyle.TextAlign] = "right";
00759             cell.Controls.Add(btnDelete);
00760             row.Cells.Add(cell);
00761 
00762             tab.Rows.Add(row);
00763 
00764             row = new HtmlTableRow();
00765             cell = new HtmlTableCell();
00766             cell.ColSpan = 2;
00767             cell.Controls.Add(file);
00768 
00769             row.Cells.Add(cell);
00770 
00771             row.Cells.Add(cell);
00772             tab.Rows.Add(row);
00773 
00774             col2.Controls.Add(tab);
00775             // Required fields
00776             if (fieldData.Field.Necessity == Field.NecessityType.Required && fieldData.Value=="")
00777             {
00778                 UserData currentUser = (UserData)table.Page.Session[UI.Common.Constants.CURRENT_USER_TAG];
00779                 string translatedMessage = RAIS.ApplicationLogicLayer.Localisation.Translate(RAIS.Common.Messages.FIELD_IS_MANDATORY,
00780                                                                                             RAIS.Common.Messages.TRANSLATION_CONTEXT,
00781                                                                                             RAIS.Common.Constants.DEFAULT_LANGUAGE,
00782                                                                                             currentUser.Language);
00783 
00784                 RequiredFieldValidator validator = new RequiredFieldValidator();
00785                 validator.ControlToValidate = file.ID;
00786                 validator.ErrorMessage = translatedMessage;
00787 
00788                 col3.Controls.Add(validator);
00789             }
00790         }
00791 
00792         static private void InitializeField(HtmlTable htmlTable, FieldData fieldData, int controlNumber, int rowNumber)
00793         {
00794             HtmlTable controlTable = htmlTable.Rows[rowNumber].Cells[1].Controls[controlNumber] as HtmlTable ;
00795             if (controlTable!=null)
00796             {
00797                 Button deleteButon = controlTable.Rows[0].Cells[1].Controls[0] as Button;
00798                 if (fieldData.Field.Necessity == Field.NecessityType.Required || fieldData.Value == ""
00799                     || !File.Exists(ConfigurationManager.AppSettings["UploadDirectory"] + "\\" + fieldData.Value))
00800                     deleteButon.Style["display"] = "none";
00801                 else
00802                 {
00803                     deleteButon.CommandName = fieldData.Field.Name;
00804                     deleteButon.CommandArgument = fieldData.Value;
00805                 }
00806 
00807                 HyperLink link = controlTable.Rows[0].Cells[0].Controls[0] as HyperLink;
00808                 if (link != null)
00809                 {
00810                     if (fieldData.Value != "" && !File.Exists(ConfigurationManager.AppSettings["UploadDirectory"] + "\\" + fieldData.Value))
00811                     {
00812                         link.NavigateUrl = "";
00813                         link.Text = fieldData.Value + " is not exists";
00814                         link.ForeColor = System.Drawing.Color.Red;
00815                     }
00816                     else
00817                     {
00818                         link.ForeColor = System.Drawing.Color.Black;
00819                         if (htmlTable.Page.Session[Constants.DOWNLOAD_FILES_LIST] == null)
00820                             htmlTable.Page.Session[Constants.DOWNLOAD_FILES_LIST] = new List<string>();
00821                         ((List<string>)htmlTable.Page.Session[Constants.DOWNLOAD_FILES_LIST]).Add(fieldData.Value);
00822                         link.NavigateUrl = "~//Download.aspx?FileName=" + fieldData.Value;
00823                         link.Text = fieldData.Value;
00824                     }
00825                 }
00826             }
00827         }
00828         }
00829 }